package com.zhiyizhen.handheld.net.response;

import com.zhiyizhen.handheld.common.constant.ResponseCode;
import com.zhiyizhen.handheld.net.BaseObserver;
import com.zhiyizhen.handheld.net.ResponseException;

public abstract class ResponseObserver<T> extends BaseObserver<ResponseData<T>> {

    @Override
    public final void onNext(ResponseData<T> responseData) {
        if (responseData.getCode().equals(ResponseCode.SUCCESS)) {
            onSuccess(responseData);
        } else {
            onError(new ResponseException(responseData));
        }
    }

    protected abstract void onSuccess(ResponseData<T> responseData);
}
